package com.pengtu.web.contract;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import com.pengtu.entity.contract.Inventor;
import com.pengtu.entity.contract.Itemlist;
import com.pengtu.service.contract.AccordingManager;
import com.pengtu.utils.web.Struts2Utils;
import com.pengtu.web.BaseActionSupport;
@Results({@Result(name="inventor",location="${ctx}/contract/itemlist!input.action?cid=${cid}",type="redirect")})
public class ItemlistAction extends BaseActionSupport<Itemlist> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Itemlist itemlist;
	private List<Itemlist> itemlistList=new ArrayList<Itemlist>();
	private AccordingManager accordingManager;
	private String id;
	private String cid;
	private String [] itemArray= {};

	
	public String getCid() {
		return cid;
	}

	public void setCid(String cid) {
		this.cid = cid;
	}

	public String[] getItemArray() {
		return itemArray;
	}

	public void setItemArray(String[] itemArray) {
		this.itemArray = itemArray;
	}

	public AccordingManager getAccordingManager() {
		return accordingManager;
	}
	
	public Itemlist getItemlist() {
		return itemlist;
	}

	public void setItemlist(Itemlist itemlist) {
		this.itemlist = itemlist;
	}

	public List<Itemlist> getItemlistList() {
		return itemlistList;
	}

	public void setItemlistList(List<Itemlist> itemlistList) {
		this.itemlistList = itemlistList;
	}

	@Autowired
	public void setAccordingManager(AccordingManager accordingManager) {
		this.accordingManager = accordingManager;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Override
	public Itemlist getModel() {
		// TODO Auto-generated method stub
		return  itemlist;
	}

	@Override
	public String list() throws Exception {
		itemlistList = accordingManager.findItemlistAll();
		List<Inventor> Inventors = accordingManager.findInventorOrdById(cid, cid);
		Struts2Utils.getRequest().setAttribute("Inventors", Inventors);
		return SUCCESS;
	}
	
	public String all() throws Exception {
		itemlistList = accordingManager.findItemlistAll();
		return "all";
	}
	
	@Override
	public String input() throws Exception {
		return INPUT;
		
	}

	@Override
	public String save() throws Exception {
		return RELOAD;
	}

	@Override
	public String delete() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected void prepareModel() throws Exception {
		// TODO Auto-generated method stub
		if(StringUtils.isNotEmpty(id)){
			itemlist=accordingManager.findItemlistByValue("id",id);
		}else{
			itemlist=new Itemlist();
		}
		
	}
	

}
